import pandas as pd
from elasticsearch import Elasticsearch
import os
import pathlib
import sys

project_path = pathlib.Path(os.path.abspath(__file__)).parent.parent.parent
sys.path.append(str(project_path))
from settings import es_host, es_setting_sheet, excel_path
from utility.import_log import flog

log = flog(__file__)

es = Elasticsearch()

es_setting = pd.read_excel(excel_path, sheet_name=es_setting_sheet)
log.info(f'成功读取Excel文件{es_setting_sheet}页配置信息')
try:
    for _, row in es_setting.iterrows():
        index_name = row[0]
        es.indices.delete(index=index_name)
        log.info(f'{index_name} delete')
except Exception as ex:
    log.error('索引删除失败!失败信息如下:')
    log.error(str(ex))
